<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<title>智慧团建系统-考勤员添加</title>

		<!-- css -->
		<link type="text/css" rel="stylesheet" charset="utf-8" href="../../asset/bootstrap/css/bootstrap.css">
		<link rel="stylesheet" type="text/css"  href="../../asset/css/comm.css" />
		<link type="text/css" rel="stylesheet" charset="utf-8" href="../../asset/css/cys.css">
		<script type="text/javascript" src="../../asset/angular/angularAll.js"></script>

		<style type="text/css">
			.inner_line{background:none}
			.searBOX{margin-left:0}
			.searBOX .inpBox{width:75%;}
			.searBOX .inpBox .left{ width: 32%;min-width: 116px;}
			.btn.checkBtn{line-height:18px}
			.pull-right .btn{    padding: 0 16px;width: auto}
		</style>
	</head>
	<body class="qm_bgcolor">
		<div ng-app="myApp" ng-controller="myCtrl as ctrl">
			<div class="searBOX">
				<div class="inpBox">
					<span class="left">姓名/工号/学号：</span>
					<input type="text" class="inptext" placeholder="请输入关键字" ng-model="ctrl.kqyQueryParam">
				</div>
				<a href="javascript:;" ng-click="ctrl.query()" type="submit" class="btn checkBtn">查询</a>
			</div>
			<div  class="inner_line index-main">
				<div style="width:100%;text-align:center;position:absolute;background:#3dc878;padding:6px 10px;color:#fff;right:0;top:59px" class="form-group text-success" ng-show="ctrl.notice">{{ctrl.notice}}</div>
				<table class="newTABLE">
					<thead>
					<th style="width: 3%" class="selBOX"><input ng-change="changeAll()" ng-model="selectAll" type="checkbox"></th>
					<th style="width: 27%">工号/学号</th>
					<th style="width: 27%">姓名</th>
					<th style="width: 18%">操作</th>
					</thead>
					<tr ng-repeat="item in ctrl.entities.content" ng-init="outerIndex=$index" ng-click="changeCurrents(item, $event)">
						<td class="selBOX"><input ng-model="item.checked" ng-click="changeCurrent(item, $event)" type="checkbox"></td>
						<td>{{item.kqyh}}</td>
						<td>{{item.kqy}}</td>
						<td>
							<a href="javascript:;" class="btn_w clear" ng-click="ctrl.add(item)">添加</a>
						</td>
					</tr>
				</table>
				<div class="panel-body">
					共有记录：
					<span>{{ctrl.entities.totalElements}}</span>
					条
					<div style="width:40%" class="pull-right" ng-include="'../../components/page.html'"></div>
				</div>
			</div>
		</div>

		<script>
			var app = angular.module('myApp', []);

            function configHttp($httpProvider) {
                $httpProvider.defaults.withCredentials = true;
                $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
                var param = function (obj) {
                    var query = '', name, value, fullSubName, subName, subValue, innerObj, i;
                    for (name in obj) {
                        value = obj[name];
                        if (value instanceof Array) {
                            for (i = 0; i < value.length; ++i) {
                                subValue = value[i];
                                if (angular.isObject(subValue)) {
                                    fullSubName = name + '[' + i + ']';
                                } else {
                                    fullSubName = name; // + '[' + i + ']';
                                }
                                innerObj = {};
                                innerObj[fullSubName] = subValue;
                                query += param(innerObj) + '&';
                            }
                        } else if (angular.isDate(value)) {
                            query += encodeURIComponent(name) + '=' + encodeURIComponent(value.getTime()) + '&';
                        } else if (value instanceof Object) {
                            for (subName in value) {
                                subValue = value[subName];
                                fullSubName = name + '.' + subName;
                                innerObj = {};
                                innerObj[fullSubName] = subValue;
                                query += param(innerObj) + '&';
                            }
                        } else if (value !== undefined && value !== null)
                            query += encodeURIComponent(name) + '=' + encodeURIComponent(value) + '&';
                    }
                    return query.length ? query.substr(0, query.length - 1) : query;
                }
                $httpProvider.defaults.transformRequest = [function (data) {
                    return angular.isObject(data) && String(data) !== '[object File]' ? param(data) : data;
                }]
                $httpProvider.defaults.transformResponse = [function defaultHttpResponseTransform(data, headers) {
                    if (angular.isString(data)) {
                        var tempData = data.replace(/^\)]\}',?\n/, "").trim();
                        if (tempData) {
                            var contentType = headers("Content-Type");
                            if (contentType && contentType.indexOf('application/json') === 0) {
                                try {
                                    data = angular.fromJson(tempData);
                                } catch (error) {
                                }
                            }
                        }
                    }
                    return data;
                }]
            }
            app.config(configHttp);
            app.config(function ($controllerProvider) {
                $controllerProvider.allowGlobals && $controllerProvider.allowGlobals();
            })

            app.controller('myCtrl', function($scope, $http) {
                var ctrl = this;
                var listUrl = '../../kq/listUser';
                var param = {}
                $http.post(listUrl, param).success(function (r) {
                    ctrl.entities = r;
                })

                this.getQueryParams = function (ctrl) {
                    var param = {}
                    angular.forEach(ctrl, function (v, k) {
                        k = k + ''
                        var i = k.lastIndexOf('QueryParam')
                        if ((i > 0 && i == (k.length - 10)) && v != '') {
                            param[k.substring(0, i)] = angular.isFunction(v) ? v() : v
                        }
                    })
                    param.pageNumber = ctrl.pageNumber
                    param.pageSize = ctrl.pageSize
                    return param;
                }

                //CtrlUtil.build(this, listUrl)
                this.query = function () {
                    ctrl.entities && (ctrl.entities.content = {})
                    var p = this.getQueryParams(ctrl)
                    $http.post(listUrl, p).success(function (r) {
                        ctrl.entities = r;
                    })
                }

                this.add = function (item) {
                    var postData = {kqyid: item.kqyid, kqyh: item.kqyh, kqy: item.kqy};
                    $http.post('../../kq/addKqy', postData).success(function(r) {
                        if (r) {
                            ctrl.query();
                            setTimeout(function () {
                                ctrl.notice = "";
                            },2000);
                            ctrl.notice = item.kqyh + " 添加成功! 注意：关闭弹出窗口后，请点击 刷新 按钮，重新加载数据。";
                        }
                    });
                }
			});
		</script>
	</body>
</html>